//
//  TTInitUI.m
//  TTBaseProject
//
//  Created by shny588 on 16/7/8.
//  Copyright © 2016年 tt. All rights reserved.
//

#import "TTInitUI.h"
#import "AppDelegate.h"
#import "TTTabBarController.h"
#import "TTNavigationViewController.h"
#import "TTGuidePageViewController.h"
#import "TTLoginViewController.h"

@interface TTInitUI ()

@end

@implementation TTInitUI

/**
 *  获取QYInitUI单例对象
 *
 *  @return QYInitUI单例对象
 */
+ (TTInitUI *)shared {
    static TTInitUI *sharedAccountManagerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^ {
        sharedAccountManagerInstance = [[self alloc] init];
    });
    return sharedAccountManagerInstance;
}

#pragma mark - UI
/**
 *  初始化rootViewController。如果默认账户为空，则初始化登录，否则初始化tabbar
 *
 *  @param launchOptions 入口类中启动配置
 */
- (void)initUI:(NSDictionary *)launchOptions
{
    //判断是否是第一打开使用
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"fristInstall"]){
        //加载欢迎页
        TTGuidePageViewController *guidePageVC = [[TTGuidePageViewController alloc] init];
        AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
        app.window.rootViewController = guidePageVC;
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"fristInstall"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }else{
        //判断是否登录过
        if ([[TTAccountService shared] defaultAccount]) {
            TTTabBarController *tabBarController = [[TTTabBarController alloc] init];
            AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
            app.window.rootViewController = tabBarController;
        }else {
            TTLoginViewController *loginVC = [[TTLoginViewController alloc] init];
            TTNavigationViewController *navigationViewController = [[TTNavigationViewController alloc] initWithRootViewController:loginVC];
            AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
            app.window.rootViewController = navigationViewController;
        }
    }
}

@end
